﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using FineUI;
using SDLITS.Model;
using SDLITS.Common;
using MySoft.Data;

namespace SDLITS.Web.Basic
{
    public partial class EGAuditManage : CommonBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                txt_end.SelectedDate = DateTime.Now;
            }
        }
        private void BindGrid(WhereClip wc)
        {
            Grid1.RecordCount = SDDbSession.Default.From<V_EGAuditUser>().Where(wc).Count();
            List<V_EGAuditUser> items = SDDbSession.Default.From<V_EGAuditUser>().Where(wc).Page(Grid1.PageSize, (Grid1.PageIndex + 1)).ToList();
            Grid1.DataSource = items;
            Grid1.DataBind();
        }

        protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
        {
            Grid1.PageIndex = e.NewPageIndex;
            BindGrid(GetWhere());
        }
        protected WhereClip GetWhere()
        {
            WhereClip wc = WhereClip.All;
            if (!string.IsNullOrEmpty(txt_stard.Text))
            {
                wc = wc && V_EGAuditUser._.EnterDate >= txt_stard.Text;
            }
            if (!string.IsNullOrEmpty(txt_end.Text))
            {
                wc = wc && V_EGAuditUser._.EnterDate <= txt_end.Text;
            }
            if (!string.IsNullOrEmpty(txt_card.Text))
            {
                wc = wc && V_EGAuditUser._.EGCardNoDoor == Methed.Transfer(txt_card.Text);
            }
            if (!string.IsNullOrEmpty(txt_user.Text))
            {
                wc = wc && V_EGAuditUser._.ActionOwner.Contain(txt_user.Text);
            }
            return wc;
        }

        protected void btn_search_Click(object sender, EventArgs e)
        {
            BindGrid(GetWhere());
        }
        
    }
}
